package com.example.campus.controller.user;

import com.example.campus.pojo.entity.Like;
import com.example.campus.pojo.vo.InfoLikeVO;
import com.example.campus.pojo.vo.UserLikeVO;
import com.example.campus.result.Result;
import com.example.campus.service.LikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userLikeController")
@RequestMapping("/user/like")
@Slf4j
@Api(tags = "用户端收藏相关接口")
public class LikeController {
    @Autowired
    private LikeService likeService;

    @PostMapping("/add/{infoId}")
    @ApiOperation("当前登录用户进行收藏")
    public Result add(@PathVariable("infoId") Long infoId) {
        likeService.addByUser(infoId);
        return Result.success();
    }

    @DeleteMapping("/remove/{infoId}")
    @ApiOperation("当前登录用户移除收藏")
    public Result remove(@PathVariable("infoId") Long infoId) {
        likeService.removeByUser(infoId);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("获取当前登录用户收藏列表")
    public Result<List<UserLikeVO>> getLikeList() {
        List<UserLikeVO> userLikeVOS = likeService.getLikeListByUser();
        return Result.success(userLikeVOS);
    }

    @GetMapping("/list/{infoId}")
    @ApiOperation("获取指定失物/寻物信息的收藏列表")
    public Result<List<InfoLikeVO>> getLikeList(@PathVariable("infoId") Long infoId) {
        List<InfoLikeVO> infoLikeVOs = likeService.getLikeListByInfo(infoId);
        return Result.success(infoLikeVOs);
    }

    @GetMapping("/count/{infoId}")
    @ApiOperation("获取指定失物/寻物信息的收藏数量")
    public Result<Integer> getLikeCount(@PathVariable("infoId") Long infoId) {
        Integer count = likeService.getLikeCount(infoId);
        return Result.success(count);
    }
}
